package Tests;

//TOKENIZER EXAMPLE 2
//Frans Coenen, Tuesday 18 January 2000
//Department of Computer Science, The University of Liverpool, UK

import java.io.*; 
import java.util.*;

class TokenizerExample2 {
 // Create BufferedReader class instance

 static InputStreamReader input = new InputStreamReader(System.in);
 static BufferedReader    keyboardInput = new BufferedReader(input);

 /* Main method  */

 public static void main(String[] args) throws IOException
     {
	int numberOfTokens=0;
	int numberArray[];
	int total=0;
	
	// Get a string
	
     System.out.print("Input a sequence of integers separated by " +
     		"commas (`,'): ");
	StringTokenizer data = new
			StringTokenizer(keyboardInput.readLine(),",");

	// Get number of tokens in line and initialise array
	
	numberOfTokens = data.countTokens();
	System.out.println("Number of tokens = " + numberOfTokens + "\n");
	numberArray = new int[numberOfTokens];
	
	// Isolate tokens and maintain total
	
	for (int counter=0; counter < numberOfTokens; counter++) { 
	    numberArray[counter] = new Integer(data.nextToken()).intValue();
	    System.out.println(numberArray[counter]);
	    total = total+numberArray[counter];
	    }
	    
	// Output total
	
	System.out.println("------------\n" + total + " (average = " +
			total/numberOfTokens + ")");   	
	}
}    

